package h0803;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 最大购买宝石数目
 * @date 2024/8/3 14:39
 */
public class MaxGemstonePay2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine()); //宝石数目
        int[] gemStones = new int[n];
        for (int i = 0; i < n; i++) {
            gemStones[i] = Integer.parseInt(sc.nextLine());
        }
        int value = Integer.parseInt(sc.nextLine()); //钱数
        System.out.println(getNum(gemStones, value));
    }

    private static int getNum(int[] gemStones, int value) {
        int n = gemStones.length;
        //窗口左边界
        int start = 0;
        //ans统计结果，数量
        int ans=0;
        //窗口总和
        int currentSum = 0;
        for (int end = 0; end < n; end++) {
            currentSum +=gemStones[end];

            //调整窗口
            while (currentSum>value){
                currentSum-=gemStones[start];
                start++;
            }
            ans=Math.max(ans,end-start+1);
        }
        return ans;
    }
}
